{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9fd54a32",
   "metadata": {},
   "source": [
    "<a href=\"https://colab.research.google.com/github/jerryjliu/llama_index/blob/main/docs/examples/llm/openai.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9e3a8796-edc8-43f2-94ad-fe4fb20d70ed",
   "metadata": {},
   "source": [
    "# Fireworks"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "081d07d2",
   "metadata": {},
   "source": [
    "If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3f6f8702",
   "metadata": {},
   "outputs": [],
   "source": [
    "%pip install llama-index-llms-fireworks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "83ea30ee",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: llama-index in /home/bennyfirebase/conda/lib/python3.9/site-packages (0.10.6)\n",
      "Requirement already satisfied: llama-index-embeddings-openai<0.2.0,>=0.1.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index) (0.1.5)\n",
      "Requirement already satisfied: llama-index-multi-modal-llms-openai<0.2.0,>=0.1.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index) (0.1.3)\n",
      "Requirement already satisfied: llama-index-readers-file<0.2.0,>=0.1.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index) (0.1.4)\n",
      "Requirement already satisfied: llama-index-llms-openai<0.2.0,>=0.1.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index) (0.1.5)\n",
      "Requirement already satisfied: llama-index-question-gen-openai<0.2.0,>=0.1.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index) (0.1.2)\n",
      "Requirement already satisfied: llama-index-core<0.11.0,>=0.10.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index) (0.10.9)\n",
      "Requirement already satisfied: llama-index-program-openai<0.2.0,>=0.1.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index) (0.1.3)\n",
      "Requirement already satisfied: llama-index-legacy<0.10.0,>=0.9.48 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index) (0.9.48)\n",
      "Requirement already satisfied: llama-index-agent-openai<0.2.0,>=0.1.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index) (0.1.4)\n",
      "Requirement already satisfied: nest-asyncio<2.0.0,>=1.5.8 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index) (1.6.0)\n",
      "Requirement already satisfied: httpx in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index) (0.26.0)\n",
      "Requirement already satisfied: tqdm<5.0.0,>=4.66.1 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index) (4.66.2)\n",
      "Requirement already satisfied: numpy in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index) (1.26.4)\n",
      "Requirement already satisfied: pillow>=9.0.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index) (10.2.0)\n",
      "Requirement already satisfied: dataclasses-json in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index) (0.6.4)\n",
      "Requirement already satisfied: tenacity<9.0.0,>=8.2.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index) (8.2.3)\n",
      "Requirement already satisfied: networkx>=3.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index) (3.2.1)\n",
      "Requirement already satisfied: aiohttp<4.0.0,>=3.8.6 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index) (3.9.3)\n",
      "Requirement already satisfied: PyYAML>=6.0.1 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index) (6.0.1)\n",
      "Requirement already satisfied: SQLAlchemy[asyncio]>=1.4.49 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index) (2.0.27)\n",
      "Requirement already satisfied: tiktoken>=0.3.3 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index) (0.6.0)\n",
      "Requirement already satisfied: openai>=1.1.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index) (1.12.0)\n",
      "Requirement already satisfied: pandas in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index) (2.2.0)\n",
      "Requirement already satisfied: deprecated>=1.2.9.3 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index) (1.2.14)\n",
      "Requirement already satisfied: dirtyjson<2.0.0,>=1.0.8 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index) (1.0.8)\n",
      "Requirement already satisfied: fsspec>=2023.5.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index) (2024.2.0)\n",
      "Requirement already satisfied: nltk<4.0.0,>=3.8.1 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index) (3.8.1)\n",
      "Requirement already satisfied: typing-inspect>=0.8.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index) (0.9.0)\n",
      "Requirement already satisfied: llamaindex-py-client<0.2.0,>=0.1.13 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index) (0.1.13)\n",
      "Requirement already satisfied: requests>=2.31.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index) (2.31.0)\n",
      "Requirement already satisfied: typing-extensions>=4.5.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-core<0.11.0,>=0.10.0->llama-index) (4.9.0)\n",
      "Requirement already satisfied: bs4<0.0.3,>=0.0.2 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-readers-file<0.2.0,>=0.1.0->llama-index) (0.0.2)\n",
      "Requirement already satisfied: pymupdf<2.0.0,>=1.23.21 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-readers-file<0.2.0,>=0.1.0->llama-index) (1.23.25)\n",
      "Requirement already satisfied: beautifulsoup4<5.0.0,>=4.12.3 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-readers-file<0.2.0,>=0.1.0->llama-index) (4.12.3)\n",
      "Requirement already satisfied: pypdf<5.0.0,>=4.0.1 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llama-index-readers-file<0.2.0,>=0.1.0->llama-index) (4.0.2)\n",
      "Requirement already satisfied: async-timeout<5.0,>=4.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.0->llama-index) (4.0.3)\n",
      "Requirement already satisfied: multidict<7.0,>=4.5 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.0->llama-index) (6.0.5)\n",
      "Requirement already satisfied: aiosignal>=1.1.2 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.0->llama-index) (1.3.1)\n",
      "Requirement already satisfied: attrs>=17.3.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.0->llama-index) (23.2.0)\n",
      "Requirement already satisfied: yarl<2.0,>=1.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.0->llama-index) (1.9.4)\n",
      "Requirement already satisfied: frozenlist>=1.1.1 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from aiohttp<4.0.0,>=3.8.6->llama-index-core<0.11.0,>=0.10.0->llama-index) (1.4.1)\n",
      "Requirement already satisfied: soupsieve>1.2 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from beautifulsoup4<5.0.0,>=4.12.3->llama-index-readers-file<0.2.0,>=0.1.0->llama-index) (2.5)\n",
      "Requirement already satisfied: wrapt<2,>=1.10 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from deprecated>=1.2.9.3->llama-index-core<0.11.0,>=0.10.0->llama-index) (1.16.0)\n",
      "Requirement already satisfied: pydantic>=1.10 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from llamaindex-py-client<0.2.0,>=0.1.13->llama-index-core<0.11.0,>=0.10.0->llama-index) (2.6.1)\n",
      "Requirement already satisfied: anyio in /home/bennyfirebase/conda/lib/python3.9/site-packages (from httpx->llama-index-core<0.11.0,>=0.10.0->llama-index) (4.3.0)\n",
      "Requirement already satisfied: httpcore==1.* in /home/bennyfirebase/conda/lib/python3.9/site-packages (from httpx->llama-index-core<0.11.0,>=0.10.0->llama-index) (1.0.3)\n",
      "Requirement already satisfied: sniffio in /home/bennyfirebase/conda/lib/python3.9/site-packages (from httpx->llama-index-core<0.11.0,>=0.10.0->llama-index) (1.3.0)\n",
      "Requirement already satisfied: idna in /home/bennyfirebase/conda/lib/python3.9/site-packages (from httpx->llama-index-core<0.11.0,>=0.10.0->llama-index) (3.6)\n",
      "Requirement already satisfied: certifi in /home/bennyfirebase/conda/lib/python3.9/site-packages (from httpx->llama-index-core<0.11.0,>=0.10.0->llama-index) (2024.2.2)\n",
      "Requirement already satisfied: h11<0.15,>=0.13 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from httpcore==1.*->httpx->llama-index-core<0.11.0,>=0.10.0->llama-index) (0.14.0)\n",
      "Requirement already satisfied: joblib in /home/bennyfirebase/conda/lib/python3.9/site-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.0->llama-index) (1.3.2)\n",
      "Requirement already satisfied: regex>=2021.8.3 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.0->llama-index) (2023.12.25)\n",
      "Requirement already satisfied: click in /home/bennyfirebase/conda/lib/python3.9/site-packages (from nltk<4.0.0,>=3.8.1->llama-index-core<0.11.0,>=0.10.0->llama-index) (8.1.7)\n",
      "Requirement already satisfied: distro<2,>=1.7.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from openai>=1.1.0->llama-index-core<0.11.0,>=0.10.0->llama-index) (1.9.0)\n",
      "Requirement already satisfied: PyMuPDFb==1.23.22 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from pymupdf<2.0.0,>=1.23.21->llama-index-readers-file<0.2.0,>=0.1.0->llama-index) (1.23.22)\n",
      "Requirement already satisfied: urllib3<3,>=1.21.1 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.0->llama-index) (2.2.1)\n",
      "Requirement already satisfied: charset-normalizer<4,>=2 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from requests>=2.31.0->llama-index-core<0.11.0,>=0.10.0->llama-index) (3.3.2)\n",
      "Requirement already satisfied: greenlet!=0.4.17 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from SQLAlchemy[asyncio]>=1.4.49->llama-index-core<0.11.0,>=0.10.0->llama-index) (3.0.3)\n",
      "Requirement already satisfied: mypy-extensions>=0.3.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from typing-inspect>=0.8.0->llama-index-core<0.11.0,>=0.10.0->llama-index) (1.0.0)\n",
      "Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from dataclasses-json->llama-index-core<0.11.0,>=0.10.0->llama-index) (3.20.2)\n",
      "Requirement already satisfied: python-dateutil>=2.8.2 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from pandas->llama-index-core<0.11.0,>=0.10.0->llama-index) (2.8.2)\n",
      "Requirement already satisfied: pytz>=2020.1 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from pandas->llama-index-core<0.11.0,>=0.10.0->llama-index) (2024.1)\n",
      "Requirement already satisfied: tzdata>=2022.7 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from pandas->llama-index-core<0.11.0,>=0.10.0->llama-index) (2024.1)\n",
      "Requirement already satisfied: exceptiongroup>=1.0.2 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from anyio->httpx->llama-index-core<0.11.0,>=0.10.0->llama-index) (1.2.0)\n",
      "Requirement already satisfied: packaging>=17.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from marshmallow<4.0.0,>=3.18.0->dataclasses-json->llama-index-core<0.11.0,>=0.10.0->llama-index) (23.2)\n",
      "Requirement already satisfied: annotated-types>=0.4.0 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.13->llama-index-core<0.11.0,>=0.10.0->llama-index) (0.6.0)\n",
      "Requirement already satisfied: pydantic-core==2.16.2 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from pydantic>=1.10->llamaindex-py-client<0.2.0,>=0.1.13->llama-index-core<0.11.0,>=0.10.0->llama-index) (2.16.2)\n",
      "Requirement already satisfied: six>=1.5 in /home/bennyfirebase/conda/lib/python3.9/site-packages (from python-dateutil>=2.8.2->pandas->llama-index-core<0.11.0,>=0.10.0->llama-index) (1.16.0)\n",
      "Note: you may need to restart the kernel to use updated packages.\n"
     ]
    }
   ],
   "source": [
    "%pip install llama-index"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b007403c-6b7a-420c-92f1-4171d05ed9bb",
   "metadata": {},
   "source": [
    "## Basic Usage"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8ead155e-b8bd-46f9-ab9b-28fc009361dd",
   "metadata": {},
   "source": [
    "#### Call `complete` with a prompt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "60be18ae-c957-4ac2-a58a-0652e18ee6d6",
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index.llms.fireworks import Fireworks\n",
    "\n",
    "resp = Fireworks().complete(\"Paul Graham is \")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ac2cbebb-a444-4a46-9d85-b265a3483d68",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Graham is a well-known essayist, programmer, and startup entrepreneur. He is best known for co-founding the venture capital firm, Y Combinator, which has funded and supported numerous successful startups, including Dropbox, Airbnb, and Reddit. Prior to Y Combinator, Graham co-founded Viaweb, one of the first software-as-a-service (SaaS) companies, which was later acquired by Yahoo.\n",
      "\n",
      "Graham is also known for his influential essays on startups, programming, and personal productivity, which he publishes on his website, www.paulgraham.com. His writing is widely read and respected in the tech and startup communities, and he has been credited with helping to shape the way many people think about startups and entrepreneurship.\n",
      "\n",
      "In addition to his work in technology and venture capital, Graham has a strong interest in education and has written extensively about the need for reform in the American education system. He is a graduate of Cornell University and holds a Ph.D. in computer science from Harvard University.\n"
     ]
    }
   ],
   "source": [
    "print(resp)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "14831268-f90f-499d-9d86-925dbc88292b",
   "metadata": {},
   "source": [
    "#### Call `chat` with a list of messages"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bbe29574-4af1-48d5-9739-f60652b6ce6c",
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index.core.llms import ChatMessage\n",
    "from llama_index.llms.fireworks import Fireworks\n",
    "\n",
    "messages = [\n",
    "    ChatMessage(\n",
    "        role=\"system\", content=\"You are a pirate with a colorful personality\"\n",
    "    ),\n",
    "    ChatMessage(role=\"user\", content=\"What is your name\"),\n",
    "]\n",
    "resp = Fireworks().chat(messages)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9cbd550a-0264-4a11-9b2c-a08d8723a5ae",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "assistant: Arr matey, ye be askin' for me name? Well, I be known as Captain Redbeard the Terrible! Me crew says I'm a right colorful character, with me flamboyant red beard and me love for all things bright and bold. So hoist the Jolly Roger and let's set sail for adventure, yarr!\n"
     ]
    }
   ],
   "source": [
    "print(resp)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2ed5e894-4597-4911-a623-591560f72b82",
   "metadata": {},
   "source": [
    "## Streaming"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4cb7986f-aaed-42e2-abdd-f274f6d4fc59",
   "metadata": {},
   "source": [
    "Using `stream_complete` endpoint"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d43f17a2-0aeb-464b-a7a7-732ba5e8ef24",
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index.llms.fireworks import Fireworks\n",
    "\n",
    "llm = Fireworks()\n",
    "resp = llm.stream_complete(\"Paul Graham is \")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0214e911-cf0d-489c-bc48-9bb1d8bf65d8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a well-known essayist, programmer, and venture capitalist. He is best known for co-founding the startup incubator and venture capital firm, Y Combinator, which has funded and helped grow many successful tech companies including Dropbox, Airbnb, and Reddit. Graham is also known for his influential essays on startups, technology, and programming, which he publishes on his website. Prior to his work in venture capital, Graham was a successful programmer and entrepreneur, co-founding the company Viaweb (later acquired by Yahoo) which developed the first web-based application for building online stores."
     ]
    }
   ],
   "source": [
    "for r in resp:\n",
    "    print(r.delta, end=\"\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "40350dd8-3f50-4a2f-8545-5723942039bb",
   "metadata": {},
   "source": [
    "Using `stream_chat` endpoint"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bc636e65-a67b-4dcd-ac60-b25abc9d8dbd",
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index.llms.fireworks import Fireworks\n",
    "from llama_index.core.llms import ChatMessage\n",
    "\n",
    "llm = Fireworks()\n",
    "messages = [\n",
    "    ChatMessage(\n",
    "        role=\"system\", content=\"You are a pirate with a colorful personality\"\n",
    "    ),\n",
    "    ChatMessage(role=\"user\", content=\"What is your name\"),\n",
    "]\n",
    "resp = llm.stream_chat(messages)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4475a6bc-1051-4287-abce-ba83324aeb9e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Arr matey, ye be askin' for me name? Well, I be known as Captain Redbeard the Terrible! Me crew says I'm a bit of a character, always crackin' me jokes and singin' shanties. But don't let me fool ya, I be a fierce pirate, feared by all who sail the seven seas!"
     ]
    }
   ],
   "source": [
    "for r in resp:\n",
    "    print(r.delta, end=\"\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "009d3f1c-ef35-4126-ae82-0b97adb746e3",
   "metadata": {},
   "source": [
    "## Configure Model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e973e3d1-a3c9-43b9-bee1-af3e57946ac3",
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index.llms.fireworks import Fireworks\n",
    "\n",
    "llm = Fireworks(model=\"accounts/fireworks/models/firefunction-v1\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e2c9bcf6-c950-4dfc-abdc-598d5bdedf40",
   "metadata": {},
   "outputs": [],
   "source": [
    "resp = llm.complete(\"Paul Graham is \")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2edc85ca-df17-4774-a3ea-e80109fa1811",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Paul Graham is an English-American computer scientist, entrepreneur, venture capitalist, author, and blogger. He is known for co-founding the web-based application platform Viaweb, which was acquired by Yahoo! in 1998. He is also the founder of the startup accelerator Y Combinator.\n"
     ]
    }
   ],
   "source": [
    "print(resp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "026fdb77-b61f-4571-8eaf-4a51e8415458",
   "metadata": {},
   "outputs": [],
   "source": [
    "messages = [\n",
    "    ChatMessage(\n",
    "        role=\"system\", content=\"You are a pirate with a colorful personality\"\n",
    "    ),\n",
    "    ChatMessage(role=\"user\", content=\"What is your name\"),\n",
    "]\n",
    "resp = llm.chat(messages)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2286a16c-188b-437f-a1a3-4efe299b759d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "assistant: My name is Captain Redbeard, but you can call me Red for short.\n"
     ]
    }
   ],
   "source": [
    "print(resp)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a2782f06",
   "metadata": {},
   "source": [
    "## Set API Key at a per-instance level\n",
    "If desired, you can have separate LLM instances use separate API keys."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "015c2d39",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a well-known essayist, programmer, and venture capitalist. He is best known for co-founding the startup incubator and venture capital firm, Y Combinator, which has funded and helped grow many successful tech companies including Dropbox, Airbnb, and Reddit. Graham is also known for his influential essays on startups, technology, and programming, which he publishes on his website, www.paulgraham.com. Prior to his work in venture capital, Graham was a successful entrepreneur and programmer, co-founding the company Viaweb (later acquired by Yahoo) and writing the programming language Arc.\n"
     ]
    }
   ],
   "source": [
    "from llama_index.llms.fireworks import Fireworks\n",
    "\n",
    "llm = Fireworks(\n",
    "    model=\"accounts/fireworks/models/firefunction-v1\", api_key=\"BAD_KEY\"\n",
    ")\n",
    "resp = Fireworks().complete(\"Paul Graham is \")\n",
    "print(resp)"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
